<?
if($this->input->get('logout')=='1'){
	$this->session->delete('clientid');
}

echo '<div class="clientlogin">';

$client=ORM::factory('client', $this->session->get('clientid'));
$clientdata=$client->orderby('category')->clientdata->as_array();
$containers=ORM::factory('clientdata')->containers;

if($client->id!=0){
	echo '<h1>Daten von '.$client->title.'</h1>';
	echo '<div class="logout_navi">'.html::anchor($this->uri->string().'?logout=1','logout').'</div>';
	foreach($containers as $key=>$container){
		$client->reload();
		$datas=$client->where('category', $key)->clientdata;
		if($datas->count()>0){
		
			echo '<div class="container">';
			echo '<h1>'.$container.'</h1>';
			foreach($datas as $data){
				echo '<div class="data">';
				if($data->title==''){
					$data->title='datei';
				}			
				echo html::file_anchor( $data->url, $data->origfilename, array('target'=>'_blank'));	
				echo '</div>';
			
			}
			echo '</div>';
		}
	}
}else{
	if($this->input->post('username')!=''){	
		$clientid=$client->login($this->input->post('username'),$this->input->post('password'));
		$this->session->set('clientid',$clientid);
		unset($_POST);
		url::redirect($this->uri->string());
	}
	
	echo form::open();
	echo '<p>';
	echo form::label('username', 'Username');
	echo form::input('username');
	echo '</p>';
	echo '<p>';
	echo form::label('password', 'Password');
	echo form::password('password');
	echo '</p>';
	
	echo '<p>';
	echo form::label('submit', '&nbsp;');
	echo form::submit('submit','Submit');
	echo '</p>';
	
	echo form::close();
}

echo '</div>';



/*
$client=ORM::factory('client', $this->session->get('clientid'));
if($client->id!=0){
	echo '<h1>logged in as '.$client->title.'</h1>';
	echo html::anchor($this->uri->string().'?logout=1','logout');
	foreach($client->orderby('category')->clientdata as $data){
		echo '<div>';
		echo '<h1>'.$data->title.'</h1>';
		echo '<p>'.html::file_anchor( $data->url, 'dateilink', array('target'=>'_blank')).'</p>';	
		echo '</div>';
	}
}else{

	if($this->input->post('username')!=''){	
		$clientid=$client->login($this->input->post('username'),$this->input->post('password'));
		$this->session->set('clientid',$clientid);
		unset($_POST);
		url::redirect($this->uri->string());
	
	}
	
	echo form::open();
	echo '<p>';
	echo form::label('username', 'Username');
	echo form::input('username');
	echo '</p>';
	echo '<p>';
	echo form::label('password', 'Password');
	echo form::password('password');
	echo '</p>';


}

*/

?>